package day10.homework;

import java.io.*;
import java.net.Socket;
import java.util.*;

public class Client {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        while (true) {
           // 127.0.0.1:本地ip 也可以使用localhost
            Socket s = new Socket("127.0.0.1", 8881);

           System.out.println("--------------------------------------------");
           System.out.println("请输入你需要的操作");
           System.out.println("1.添加   2.删除   3.查数据(输入数据就查找该数据,否则查找所有数据)   4.修改   0退出");
           Scanner in = new Scanner(System.in);
           Student st = new Student();
           int op = in.nextInt();
           if (op == 0) System.exit(0);
            if (op != 3){
                System.out.println("请输入要操作的学生ID:");
                st.setId(in.nextInt());

                System.out.println("请输入要操作的学生名字:");
                st.setName(in.next());
            }

           OutputStream os = s.getOutputStream();
           ObjectOutputStream oos = new ObjectOutputStream(os);

           Map<Integer, Student> map = new HashMap<>();

           if (op == 3) {
               map.put(3, null);
           } else {
               map.put(op, st);
           }
           System.out.println(map.size());
           oos.writeObject(map);

           //4关闭资源
           os.close();
           s.close();
           oos.close();
       }
    }
}
